home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bchelp10.zip / TI660.ASC < prev    next >
Text File  |  1991-09-17  |  1KB  |  67 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  660
  9.   VERSION  :  All
  10.        OS  :  PC DOS
  11.      DATE  :  September 17, 1991                       PAGE  :  1/1
  12.  
  13.     TITLE  :  Dynamically Allocating >64K in Windows 3.0
  14.  
  15.  
  16.  
  17.  
  18.  
  19.   In Windows the pointer returned by malloc() is really a selector.
  20.   When you malloc()  more than 64k, Windows will  set  up  multiple
  21.   selectors.  To use  the  pointer you need to increment the offset
  22.   until it reaches 0x0000 again (it always starts at 0x0000).   You
  23.   then need to add a constant value to the segment (Petzold  says 8
  24.   for  protected  mode, 0x1000 for real mode.    See  page  295  of
  25.   Windows  3.0  Power  Programming.),  which  will  give  the  next
  26.   selector!  For example:
  27.  
  28.   /* Must be far... huge pointers do not work */
  29.   char far *pfoo;
  30.  
  31.   /* 'pfoo' points to first 64k */
  32.   pfoo = (char far *) farmalloc (1000000ul);
  33.  
  34.   /* Advance to next segment */
  35.   while (FP_OFF (pfoo) != 0x0000) pfoo++;
  36.  
  37.   /* Now points to second 64K */
  38.   pfoo = MK_FP (FP_SEG (pfoo) + 8, 0x0000);
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.